/*
 * Helstius--Basic chemistry application
 * This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 * Copyright 2012 Jaked122
 */
package org.helstius.Gui;

import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.geom.AffineTransform;
import java.util.Collection;
import java.util.List;

import org.helstius.util.Utility;

/**
 * <p>
 * Basic Chart type. Displays labeled data in a chart form.
 * </p>
 * 
 * @author Jaked122
 * 
 */
public class ProperBarChart extends Canvas implements IChart {
	public void paint(Graphics g) {
		super.paint(g);
		if (data != null && names != null) {
			int hstep = getWidth() / data.length;
			int vstep = getHeight() / Utility.max(data);
			e = new ColorGradient(Color.red, Color.blue, data.length);
			for (int v = 0; v < data.length; v++) {
				int i = (hstep * v) + (v >= 0 ? -(hstep / 2) : (hstep / 2));
				g.setColor(e.getAtStep(v));
				g.fillRect(hstep * v, 0, hstep, vstep * data[v]);
				g.setColor(Color.white);
				g.drawString(names[v], i, 10);
				g.drawRect(hstep * v, 0, hstep, vstep * data[v]);

			}
		}
	}

	String[] names;
	int[] data;
	private ColorGradient e;

	public void AddData(List<String> names, List<Integer> datum) {
		data = new int[datum.size()];
		this.names = new String[names.size()];
		for (int i = 0; i < data.length; i++) {
			data[i] = datum.get(i);
			this.names[i] = names.get(i);
		}
		repaint();
	}

	public void AddData(String[] names, int[] datum) {
		data = datum;
		this.names = names;
		this.repaint();
	}

	@Override
	public void addData(int[] data) {
		// TODO Auto-generated method stub
		this.data = data;
		repaint();
	}

	@Override
	public void setData(int[] data) {
		// TODO Auto-generated method stub
		this.data = data;
		repaint();
	}

	@Override
	public Color getElementColor(int element) {
		// TODO Auto-generated method stub
		return e.getAtStep(element);
	}

	@Override
	public int[] getData() {
		// TODO Auto-generated method stub
		return data;
	}

	@Override
	public void addNames(String[] names) {
		// TODO Auto-generated method stub
		this.names = names;
	}

	@Override
	public String[] getNames() {
		// TODO Auto-generated method stub
		return names;
	}
}
